<?php
try {
  $plugin = new stdClass();
  $plugin->folder = basename(dirname(__FILE__));
  DbUtils::add($myPdo, 'pz2_plugin', $plugin);
} catch (PDOException $e) {
}

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "user_profile`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `account` varchar(64) DEFAULT '',
         `password` varchar(64) DEFAULT '',
         `email` varchar(256) DEFAULT '',
         `shop_name` varchar(256) DEFAULT ''
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "user_page_manage`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `instance_id` int DEFAULT 0,
         `system_id` int DEFAULT 0
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_brand`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `name` varchar(256) DEFAULT '',
         `file` varchar(256) DEFAULT ''
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_category`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `parent_id` int DEFAULT 0,
         `name` varchar(256) DEFAULT '',
         `order` double DEFAULT 0,
         `file` varchar(256) DEFAULT ''
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_product`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `track_id` varchar(16) UNIQUE DEFAULT '',
         `date` date DEFAULT '0000-00-00',
         `enabled_stock` tinyint(1) DEFAULT 0,
         `enabled_delivery` tinyint(1) DEFAULT 0,
         `enabled_member_price` tinyint(1) DEFAULT 0,
         `brand_id` int DEFAULT 0,
         `category_id` int DEFAULT 0,
         `name` varchar(256) DEFAULT '',
         `price` decimal(10, 2) DEFAULT 0.00,
         `stock` int DEFAULT 0,
         `stock_alert` int DEFAULT 0,
         `intro` text,
         `details` text,
         `status` tinyint(1) DEFAULT 0,
         `sold__` int DEFAULT 0,
         `alert__` tinyint(1) DEFAULT 0
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_product_member_price`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `product_track_id` varchar(16) DEFAULT '',
         `member_id` int DEFAULT 0,
         `price` decimal(10, 2) DEFAULT 0.00
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_product_object`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `product_track_id` varchar(16) DEFAULT '',
         `attr_opt_id` varchar(256) DEFAULT '',
         `attr_opt_code` varchar(512) DEFAULT '',
         `stock` int DEFAULT 0,
         `stock_alert` int DEFAULT 0,
         `diff_price` decimal(10, 2) DEFAULT 0.00
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_product_attr`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `product_track_id` varchar(16) DEFAULT '',
         `name` varchar(256) DEFAULT ''
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_product_attr_opt`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `product_track_id` varchar(16) DEFAULT '',
         `product_attr_id` int DEFAULT 0,
         `name` varchar(256) DEFAULT '',
         `file` varchar(256) DEFAULT ''
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_product_img`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `product_track_id` varchar(16) DEFAULT '',
         `file` varchar(256) DEFAULT '',
         `is_default` tinyint(1) DEFAULT 0
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_purchase`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `product_track_id` varchar(16) DEFAULT '',
         `customer_id` int DEFAULT 0,
         `order_id` int DEFAULT 0,
         `name` varchar(256) DEFAULT '',
         `price` decimal(10, 2) DEFAULT 0.00,
         `quantity` int,
         `total` decimal(10, 2) DEFAULT 0.00,
         `attr_opt_id` varchar(256) DEFAULT '',
         `attr_opt_code` varchar(512) DEFAULT ''
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_special`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `product_id` int DEFAULT 0,
         `old_price` decimal(10, 2) DEFAULT 0.00,
         `new_price` decimal(10, 2) DEFAULT 0.00,
         `from` date DEFAULT '0000-00-00',
         `to` date DEFAULT '0000-00-00'
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_order`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `date` date DEFAULT '0000-00-00',
         `date_deliver` date DEFAULT '0000-00-00',
         `customer_id` int DEFAULT 0,
         `order_number` varchar(32) DEFAULT '',
         `is_paid` tinyint(1) DEFAULT 0,
         `is_delivered` tinyint(1) DEFAULT 0,
         `is_cancel` tinyint(1) DEFAULT 0,
         `total` decimal(10, 2) DEFAULT 0.00,
         `comment` text,
         `payment_id` int DEFAULT 0,
         `payment_name` varchar(256) DEFAULT '',
         `delivery_id` int DEFAULT 0,
         `delivery_name` varchar(256) DEFAULT '',
         `delivery_subtotal` decimal(10, 2) DEFAULT 0.00,
         `first_name` varchar(64) DEFAULT '',
         `last_name` varchar(64) DEFAULT '',
         `address1` varchar(256) DEFAULT '',
         `address2` varchar(256) DEFAULT '',
         `city` varchar(64) DEFAULT '',
         `country` varchar(64) DEFAULT '',
         `zip` varchar(64) DEFAULT '',
         `phone` varchar(64) DEFAULT '',
         `email` varchar(64) DEFAULT ''
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_customer`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `track_id` varchar(16) UNIQUE DEFAULT '',
         `member_id` int DEFAULT 0,
         `account` varchar(64) UNIQUE DEFAULT '',
         `password` varchar(64) DEFAULT '',
         `reg_date` date DEFAULT '0000-00-00',
         `last_login` date DEFAULT '0000-00-00',
         `first_name` varchar(64) DEFAULT '',
         `last_name` varchar(64) DEFAULT '',
         `phone` varchar(64) DEFAULT '',
         `is_actived` tinyint(1) DEFAULT 0,
         `ip` varchar(64) DEFAULT '',
         `ip_place` varchar(64) DEFAULT ''
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_customer_addr`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `customer_id` int DEFAULT 0,
         `first_name` varchar(64) DEFAULT '',
         `last_name` varchar(64) DEFAULT '',
         `address1` varchar(256) DEFAULT '',
         `address2` varchar(256) DEFAULT '',
         `city` varchar(64) DEFAULT '',
         `country` varchar(64) DEFAULT '',
         `zip` varchar(64) DEFAULT '',
         `phone` varchar(64) DEFAULT '',
         `email` varchar(64) DEFAULT '',
         `is_default` tinyint(1) DEFAULT 0
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_customer_member`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `title` varchar(256) DEFAULT '',
         `total_spent` decimal(10, 2) DEFAULT 0.00
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_mthd_payment`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `title` varchar(256) DEFAULT '',
         `description` text,
         `status` tinyint(1) DEFAULT 0
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . "ecom_mthd_delivery`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `title` varchar(256) DEFAULT '',
         `description` text,
         `price` decimal(10, 2) DEFAULT 0.00,
         `status` tinyint(1) DEFAULT 0
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . 'art_post' . "`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `tag_ids` text,
         `title` varchar(512) DEFAULT '',
         `content` text,
         `date` date DEFAULT '0000-00-00',
         `visitors` int DEFAULT 0
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);

$sql = "CREATE TABLE IF NOT EXISTS `" . TABLE_NAME_PREFIX_PLUGIN . 'art_tag' . "`(
         `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
         `parent_id` int DEFAULT 0,
         `name` varchar(256) DEFAULT '',
         `order` double DEFAULT 0
        ) ENGINE=MYISAM;";
$myPdo->exec($sql);
//$pass = md5(123456);
//$sql = "INSERT INTO " . TABLE_NAME_PREFIX_PLUGIN . "user_profile values (NULL, 'admin', '$pass', '', '')";
//$myPdo->exec($sql);
?>